<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

    <div id="app">
        <router-link to="/user/1">页面1</router-link>
        <router-link to="/user/2">页面2</router-link>
        <router-link to="/user/3">页面3</router-link>
        <!-- <router-link to="/user?page=1">页面1</router-link>
        <router-link to="/user?page=2">页面2</router-link>
        <router-link to="/user?page=3">页面3</router-link> -->
        <button @click="lastPage">100</button>
        <button @click="goPrev">返回</button>

        <router-view></router-view>

    </div>

    <template id="info">
        <div>
            <!-- <h3>页面{{this.$route.query.page}}，这就是动态路由利用params传递数据</h3> -->
            <h3>页面{{this.$route.params.page}}，这就是动态路由利用params传递数据</h3>
        </div>
    </template>

    <script src="../lib/Vue/vue.js"></script>
    <script src="../lib/Vue/vue-router.js"></script>
    <script>

        var router = new VueRouter({
            routes: [
                {
                    path: '/',
                    redirect: '/user'
                },
                {
                    // path: '/user',
                    path: '/user/:page',
                    name: 'pagenum',
                    component: {
                        template: '#info'
                    }
                }
            ]
        })

        var vm = new Vue({
            el: '#app',
            router,
            methods: {
                lastPage() {
                    // 使用query传参
                    // router.push({ path: '/user', query: { page: 200 } })
                    // router.push({ path: '/user?page=200' }) // 不可以
                    // 使用params传参
                    // router.push({ path: '/user/200' })
                    // router.push({ path: '/user', params: {page: 200} }) // 不可以
                    router.push({ name: 'pagenum', params: { page: 200 } })
                },
                goPrev() {
                    router.go(-1)
                }
            },
        })
    </script>
</body>

</html>